package com.dxy.lc.model.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.time.LocalDateTime;

import com.dxy.lc.model.bean.TreeVo;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * <p>
 * 用户表
 * </p>
 *
 * @author dxy
 * @since 2024-09-23
 */
@Getter
@Setter
@Accessors(chain = true)
@TableName("t_user")
public class User {

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    private String username;

    private String password;

    private String deptId;

    private String avatar;

    // 0-离线，1-在线
    private Integer status;

    private String job;

    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createdAt;

    @TableField(fill = FieldFill.INSERT)
    private Integer createdBy;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Integer updatedBy;

    private LocalDateTime lastLoginTime;

    private String lastLoginToken;

    @TableField(exist = false)
    private String deptName;

    public boolean isAdmin(){
        return "admin".equalsIgnoreCase(this.username);
    }

    public TreeVo toTreeVo(){
        return new TreeVo()
                .setId(this.id.toString())
                .setText(this.username)
                .setParentId(this.deptId)
                .setNodeType(TreeVo.NODE_TYPE_USER)
                .setVal(this);
    }

}
